﻿@*page:PrintTemplate.razor*@
@*gardener-time:2024-09-24 14:34:36*@
@page "/system_manager/print_template"
@inherits ListOperateTableBase<PrintTemplateDto, Guid, PrintTemplateEdit,PrinterLocalResource>

@{
    TableFilter<string>[] templateTypeDictFilters = DictHelper.GetCodesFromCache<PrintTemplateDto>(p => p.TemplateType)?.Select(x => { return new TableFilter<string>() { Text = Localizer[x.CodeName], Value = x.CodeValue }; }).ToArray() ?? new TableFilter<string>[0];

    TableFilter<TemplateResultType>[] templateResultTypeEnumFilters = EnumHelper.EnumToList<TemplateResultType>().Select(x => { return new TableFilter<TemplateResultType>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();

    TableFilter<IdentityType>[] identityTypeEnumFilters = EnumHelper.EnumToList<IdentityType>().Select(x => { return new TableFilter<IdentityType>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();
}
<div>
    <Table @ref="_table"
           TItem="PrintTemplateDto"
           DataSource="_datas"
           Total="_total"
           OnChange="OnChange"
           @bind-PageSize="_pageSize"
           @bind-SelectedRows="_selectedRows"
           Loading="_tableLoading.Value"
           Context="model"
           Size="ClientConstant.DefaultTableSize"
           PaginationPosition="@ClientConstant.TablePaginationPosition"
           RemoteDataSource
           RowKey="x=>x.Id">
        <TitleTemplate>
            <ResourceAuthorize ResourceKey="system_manager_print_template_search">
                <TableSearch TDto="PrintTemplateDto" @ref="this._tableSearch" OnSearch="OnTableSearch" Settings="_tableSearchSettings" CustomLocalizer="Localizer" />
            </ResourceAuthorize>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="system_manager_print_template_delete_selected">
                        <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                            @Localizer[nameof(SharedLocalResource.DeleteSelected)]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <ResourceAuthorize ResourceKey="system_manager_print_template_add">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Plus" OnClick="OnClickAdd">
                                    @Localizer[nameof(SharedLocalResource.Add)]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="system_manager_print_template_refresh">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Reload" OnClick="ReLoadTable">
                                    @Localizer[nameof(SharedLocalResource.Refresh)]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                    </Space>
                </AntDesign.Col>
            </Row>
        </TitleTemplate>
        <ColumnDefinitions>
            <Selection Hidden="@_userUnauthorizedResources["system_manager_print_template_selected"]" />

            <PropertyColumn Property="c=>c.Id" Filterable Sortable />
            <PropertyColumn Property="c=>c.Tenant" Hidden="@_userUnauthorizedResources[CommonResourceKeys.SystemTenantAdministratorKey]">
                <span>@model.Tenant?.Name</span>
            </PropertyColumn>
            <PropertyColumn Property="c=>c.TemplateKey" Filterable Sortable />
            <PropertyColumn Property="c=>c.TemplateType" Filterable Sortable Filters="templateTypeDictFilters">
                @{
                    var templateTypeCodeName = DictHelper.GetCodeNameFromCache<PrintTemplateDto>(() => model.TemplateType);
                    if (templateTypeCodeName != null)
                    {
                        templateTypeCodeName = Localizer[templateTypeCodeName];
                    }
                }
                <span>@(templateTypeCodeName)</span>
            </PropertyColumn>
            <PropertyColumn Property="c=>c.TemplateName" Filterable Sortable />
            <PropertyColumn Property="c=>c.TemplateHeight" Filterable Sortable />
            <PropertyColumn Property="c=>c.TemplateWidth" Filterable Sortable />
            <PropertyColumn Property="c=>c.TemplatePreviewImage" Filterable Sortable >
                @if (!string.IsNullOrEmpty(model.TemplatePreviewImage))
                {
                    var images = System.Text.Json.JsonSerializer.Deserialize<List<UploadFileItem>>(model.TemplatePreviewImage) ?? [];
                    <ImagePreviewGroup>
                        @foreach (var item in images)
                        {
                            <Image Width="50" Src="@item.Url" Alt="@item.FileName" />
                        }
                    </ImagePreviewGroup>
                }
            </PropertyColumn>
            <PropertyColumn Property="c=>c.TemplateResultType" Filterable Sortable Filters="templateResultTypeEnumFilters">
                <TagPro Text="@model.TemplateResultType"></TagPro>
            </PropertyColumn>
            <PropertyColumn Property="c=>c.IsLocked" Filterable Sortable>
                <ResourceAuthorize ResourceKey="system_manager_print_template_lock">
                    <Authorized>
                        <Switch @bind-Value="@model.IsLocked" OnChange="e=>OnChangeIsLocked(model,e)" Loading="_lockBtnLoading[model]"></Switch>
                    </Authorized>
                    <NotAuthorized>
                        <TagYesNo Yes="model.IsLocked"></TagYesNo>
                    </NotAuthorized>
                </ResourceAuthorize>
            </PropertyColumn>
            <PropertyColumn Property="c=>c.CreatedTime" Sortable DefaultSortOrder="@SortDirection.Descending" Format="@ClientConstant.DateTimeFormat" />
            <PropertyColumn Property="c=>c.UpdatedTime" Sortable Format="@ClientConstant.DateTimeFormat" />
            <ActionColumn>
                <Space>
                    <ResourceAuthorize ResourceKey="system_manager_print_template_update">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Edit)]" ArrowPointAtCenter="true">
                                <Button Icon="@IconType.Outline.Edit" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickEdit(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_print_template_detail">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Detail)]" ArrowPointAtCenter="true">
                                <Button Icon="@IconType.Outline.Eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_print_template_delete">
                        <SpaceItem>
                            <Tooltip Title="@Localizer[nameof(SharedLocalResource.Delete)]" ArrowPointAtCenter="true">
                                <Button Icon="@IconType.Outline.Delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnClickDelete(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                </Space>
            </ActionColumn>
        </ColumnDefinitions>
    </Table>
</div>